package cn.com.idmy.mq;

import cn.com.idmy.mq.model.MqMsg;
import cn.com.idmy.mq.model.MqSendResult;
import cn.com.idmy.mq.model.enums.MqDelayLevel;
import jakarta.annotation.Nullable;

public interface IMqProducer {

    default MqSendResult send(@Nullable String topic, String tag, String key, Object body) {
        return send(MqMsg.builder().topic(topic).tag(tag).key(key).body(body).build());
    }

    default void asyncSend(@Nullable String topic, String tag, String key, Object body, MqSendCallback cb) {
        asyncSend(MqMsg.builder().topic(topic).tag(tag).key(key).body(body).build(), cb);
    }

    default MqSendResult sendOrderly(@Nullable String topic, String tag, String key, Object body, Object shardingKey) {
        return sendOrderly(MqMsg.builder().topic(topic).tag(tag).key(key).body(body).shardingKey(shardingKey).build());
    }

    default void asyncSendOrderly(@Nullable String topic, String tag, String key, Object body, Object shardingKey, MqSendCallback cb) {
        asyncSendOrderly(MqMsg.builder().topic(topic).tag(tag).key(key).body(body).shardingKey(shardingKey).build(), cb);
    }

    default MqSendResult sendDelay(@Nullable String topic, String tag, String key, Object body, MqDelayLevel level) {
        return sendDelay(MqMsg.builder().topic(topic).tag(tag).key(key).body(body).delayLevel(level).build());
    }

    MqSendResult send(MqMsg msg);

    MqSendResult sendOrderly(MqMsg msg);

    MqSendResult sendDelay(MqMsg msg);

    void asyncSend(MqMsg msg, MqSendCallback cb);

    void asyncSendOrderly(MqMsg msg, MqSendCallback cb);

    void shutdown();

    void start();

    interface MqSendCallback {
        void onSuccess(MqSendResult result);

        void onFailure(Throwable e);
    }
}
